
import java.util.*;
public class Main
{
    public static int N = 15;
    public static int n, ret;
    public static boolean[] vis = new boolean[N];
    public static int[] arr = new int[N];
    public static void dfs(int pos) {
        if(pos == n + 1)  {// 找到⼀种合法情况
            ret++;
            return;
        }
        for(int i = 1; i <= n; i++){
            if(vis[i] == true)
                continue; // 剪枝 - i 号队员已经放过了
            if(vis[arr[i]])
                return; // 剪枝
            vis[i] = true; // 相当于已经放上 i 号队员
            dfs(pos + 1);
            vis[i] = false; // 回溯 - 恢复现场
            }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for(int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        dfs(1);
        System.out.println(ret);
    }
}
